//
//  ByDocumentCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/16.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentCell.h"
#import "ByDocumentaryCellTitleView.h"
#import "ByDocumentaryCellMoneyView.h"

#import "ByDocumentaryContentView.h"
#import "ByDocumentaryListContentView.h"

@interface ByDocumentCell ()


@property (nonatomic, strong) ByDocumentaryListContentView *contentView1;
@property (nonatomic, strong) ByDocumentaryCellMoneyView *moneyView;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *timeLabel1;
@property (nonatomic, strong) ByDocumentaryCellTitleView *titleView;

@end


@implementation ByDocumentCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByDocumentCell";
    ByDocumentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
       
    }
    return self;
}


- (void)initViews{
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.bottom.equalTo(self.contentView).offset(-10);
        make.top.equalTo(self.contentView).offset(2);
    }];
    backgroundView.backgroundColor = [UIColor whiteColor];
    backgroundView.layer.cornerRadius = 5;
    
    
    ByDocumentaryCellTitleView *titleView = [[ByDocumentaryCellTitleView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 10, 75)];
    [backgroundView addSubview:titleView];
    titleView.hidden = YES;
    self.titleView = titleView;
    titleView.tapViewBlock = ^(){
        if (self.tapViewBlock) {
            self.tapViewBlock();
        }
    };
    
    UILabel *timeLabel = [[UILabel alloc] init];
    [backgroundView addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(150);
        make.right.equalTo(backgroundView).offset(-10);
        make.height.mas_equalTo(@15);
        make.top.equalTo(backgroundView).offset(15);
    }];
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.font = FONT(12);
    timeLabel.text = @"截止时间 2018-06-26";
    timeLabel.textAlignment = NSTextAlignmentRight;
    
    
    UILabel *timeLabel1 = [[UILabel alloc] init];
    [backgroundView addSubview:timeLabel1];
    [timeLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(15);
        make.right.equalTo(timeLabel.mas_left).offset(-10);
        make.height.mas_equalTo(@15);
        make.top.equalTo(backgroundView).offset(15);
    }];
    timeLabel1.textColor = [UIColor blackColor];
    timeLabel1.font = FONT(12);
    timeLabel1.text = @"2018-06-26";
    timeLabel1.textAlignment = NSTextAlignmentLeft;
    self.timeLabel = timeLabel;
    self.timeLabel1 = timeLabel1;
    
    
    
    ByDocumentaryCellMoneyView *moneyView = [[ByDocumentaryCellMoneyView alloc] initWithFrame:CGRectMake(0, titleView.bottom, SCREEN_WIDTH - 10, 50)];
    [backgroundView addSubview:moneyView];
    self.moneyView = moneyView;
    
    CGFloat height = _netModel.ball_infoArray.count * 35 + 75;
    ByDocumentaryListContentView *contentView = [[ByDocumentaryListContentView alloc] init];
    [backgroundView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(moneyView.mas_bottom).offset(0);
        make.height.mas_equalTo(@(height));
    }];
    contentView.line.hidden = YES;
    contentView.wayLabel.hidden = NO;
    self.contentView1 = contentView;
    
    if (_netModel.lottery_type.integerValue == 2) {
        contentView.ballView.image = [UIImage imageNamed:@"lanqiu篮球"];
    }
    
    ByDocumentaryCellBottomView *bottomView = [[ByDocumentaryCellBottomView alloc] init];
    [backgroundView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(backgroundView).offset(0);
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@53);
    }];
    bottomView.betBlock = ^(){
        if (self.betBlock) {
            self.betBlock();
        };
    };
    self.bottomView = bottomView;
    
}


- (void)setIsUser:(BOOL)isUser{
    _isUser = isUser;
   
}



- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
    [self initViews];
    self.contentView1.isUser = _isUser;
    
    //
    [self.titleView.iconView sd_setImageWithURL:[NSURL URLWithString:netModel.head_pic] placeholderImage:HEAD_ICOM_IMAGE];
    self.titleView.nickLabel.text = netModel.nickname;
    self.titleView.timeLabel.text = [NSString stringWithFormat:@"截止时间:%@",[NSDate getDateForStringFotmatWithTimeInterval:netModel.end_time.integerValue formatter:@"MM-dd HH:mm"]];
    self.timeLabel.text = [NSString stringWithFormat:@"截止时间:%@",[NSDate getDateForStringFotmatWithTimeInterval:netModel.end_time.integerValue formatter:@"MM-dd HH:mm"]];
    self.timeLabel1.text = [NSString stringWithFormat:@"%@",[NSDate getDateForStringFotmatWithTimeInterval:netModel.create_time.integerValue formatter:@"yyyy-MM-dd"]];
    self.contentView1.wayLabel.text = [ByFootBallHandle getFootBallFreePassStringWithString:netModel.free_pass];
    self.contentView1.netModel = netModel;
    
    self.moneyView.leftView.valueLabel.text = [NSString stringWithFormat:@"%@元", netModel.total_amount];
    self.moneyView.centerView.valueLabel.text = [NSString stringWithFormat:@"%@人",netModel.follow_num];
    self.moneyView.rightView.valueLabel.text = [NSString stringWithFormat:@"%@元",netModel.count_amount];
    if (netModel.red_num.integerValue > 0) {
        self.titleView.recordLabel.text = [NSString stringWithFormat:@"%@连红", netModel.red_num];
    }else{
        self.titleView.recordLabel.hidden = YES;
    }
    
    //用于区分
    if (!_isUser) {
        self.titleView.hidden = NO;
        self.timeLabel.hidden = YES;
        self.timeLabel1.hidden = YES;
    }else{
        self.titleView.hidden = YES;
        self.timeLabel.hidden = NO;
        self.timeLabel1.hidden = NO;
        
        self.contentView1.valueView.valueLabel2.text = @"主队/客队";
        self.contentView1.valueView.valueLabel3.text = @"投注内容";
        self.contentView1.valueView.valueLabel4.text = @"开奖结果";
        
    }
    self.bottomView.moneyLabel.text = [NSString stringWithFormat:@"%@元",netModel.single_amount];

}

@end
